package com.wms.function.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wms.common.annotation.Log;
import com.wms.common.core.controller.BaseController;
import com.wms.common.core.domain.AjaxResult;
import com.wms.common.enums.BusinessType;
import com.wms.function.domain.TbTransPay;
import com.wms.function.service.ITbTransPayService;
import com.wms.common.utils.poi.ExcelUtil;
import com.wms.common.core.page.TableDataInfo;

/**
 * 运费Controller
 *
 * @author ruoyi
 * @date 2025-02-23
 */
@RestController
@RequestMapping("/function/pay")
@Api(tags = "运费的接口")
public class TbTransPayController extends BaseController {
    @Autowired
    private ITbTransPayService tbTransPayService;

/**
 * 查询运费列表
 */
@ApiOperation("查询运费列表")
@PreAuthorize("@ss.hasPermi('function:pay:list')")
@GetMapping("/list")
    public TableDataInfo list(TbTransPay tbTransPay) {
        startPage();
        List<TbTransPay> list = tbTransPayService.selectTbTransPayList(tbTransPay);
        return getDataTable(list);
    }

    /**
     * 导出运费列表
     */
    @ApiOperation("导出运费列表")
    @PreAuthorize("@ss.hasPermi('function:pay:export')")
    @Log(title = "运费", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbTransPay tbTransPay) {
        List<TbTransPay> list = tbTransPayService.selectTbTransPayList(tbTransPay);
        ExcelUtil<TbTransPay> util = new ExcelUtil<TbTransPay>(TbTransPay. class);
        util.exportExcel(response, list, "运费数据");
    }

    /**
     * 获取运费详细信息
     */
    @ApiOperation("获取运费详细信息")
    @PreAuthorize("@ss.hasPermi('function:pay:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@ApiParam(value = "运费ID", required = true)
                              @PathVariable("id") Long id) {
        return success(tbTransPayService.selectTbTransPayById(id));
    }

    /**
     * 新增运费
     */
    @ApiOperation("新增运费")
    @PreAuthorize("@ss.hasPermi('function:pay:add')")
    @Log(title = "运费", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@ApiParam(value = "运费实体")
                          @RequestBody TbTransPay tbTransPay) {
        return toAjax(tbTransPayService.insertTbTransPay(tbTransPay));
    }

    /**
     * 修改运费
     */
    @ApiOperation("修改运费")
    @PreAuthorize("@ss.hasPermi('function:pay:edit')")
    @Log(title = "运费", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@ApiParam(value = "运费实体")
                           @RequestBody TbTransPay tbTransPay) {
        return toAjax(tbTransPayService.updateTbTransPay(tbTransPay));
    }

    /**
     * 删除运费
     */
    @ApiOperation("删除运费")
    @PreAuthorize("@ss.hasPermi('function:pay:remove')")
    @Log(title = "运费", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tbTransPayService.deleteTbTransPayByIds(ids));
    }
}
